package com.heima.controller;

import com.heima.pojo.dto.pageDTO;
import com.heima.pojo.dto.SkuClass;
import com.heima.pojo.vo.PageVo;
import com.heima.service.skuClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
public class skuclassController {


    @Autowired
    private skuClassService skuClassService;


    @PostMapping
    public Boolean add(@RequestBody SkuClass skuClass) {

        skuClassService.add(skuClass);
        return true;
    }

    @GetMapping("/search")
    public PageVo<SkuClass> query(pageDTO pageDTO) {
        return skuClassService.query(pageDTO);
    }

    /**
     *获取分类基本信息
     * @param classId
     * @return
     */
    @GetMapping("{classId}")
    public SkuClass findById(@PathVariable String classId){
        return skuClassService.getById(classId);
    }

    @PutMapping("{classId}")
    public Boolean update(@PathVariable String classId,@RequestBody SkuClass skuClass){
        skuClass.setClassId(Integer.parseInt(classId));
        skuClassService.updateById(skuClass);
        return true;
    }

    @DeleteMapping("{classId}")
    public void Delete(@PathVariable String classId){
        skuClassService.removeById(classId);
    }
}
